<?php

class connectionDB {

	private static $connectionInstance = NULL;
	
	private $connection;
	
	static function getInstance()
	{
		if(!isset(self::$connectionInstance))
		{
			self::$connectionInstance = new connectionDB();
		}
		
		return self::$connectionInstance;
	}
	
	private function __construct()
	{
		$this->connection = mysql_connect(DB_HOST, DB_USER, DB_PWD);
		mysql_select_db(DB_NAME,$this->connection);
		
		
		
		
		
		 /*
	     * IMPOSTAZIONE LOCALE MYSQL A ITALIANO
	     */
	    $querySetItalian ="SET lc_time_names = '".DB_LOCAL."'";
	    mysql_query($querySetItalian, $this->connection);
	    
	   
	}
	
	public function getConnection()
	{
		return $this->connection;
	}
	
	public function closeConnection()
	{
		mysql_close ($this->connection);
	}
	
	public function executeUpdate($queryUpdate)
	{
		
		if(!mysql_query($queryUpdate,$this->connection))
		{
			throw new Exception('Errore nella esecuzione della query:'.$queryUpdate.' : '. mysql_error($this->connection), mysql_errno($this->connection));
		}
		
		return mysql_affected_rows($this->connection);
		
	}
	
	public function executeQuery($queryResult)
	{
		
		$result  = mysql_query($queryResult,$this->connection);
		if (!$result) {
						throw new Exception('Errore nella esecuzione della query:'.$queryResult.' : '. mysql_error($this->connection), mysql_errno($this->connection));
			
		}
		return $result;
		
	}
	
	
}
?>
